
module.exports = function ($scope, $state, $stateParams,$resource,$modal,FileUploader,toaster, items, flag, type, $modalInstance) {
  $scope.type = type;
  console.log(items);
  console.log($scope.type);
  $scope.notice = {
    'info' : {}
  }
  $scope.a = {
    'project_name' : '',
    'project_file' : '',
    'recommend_type': '',
    'project_type' : '', //项目类别(公告类型)
    'city_project' : '' // 是否为本市项目
  };
   // 详情
   $scope.getInfo = function(){
      $resource('/api/as/ggc/reviewPlanning/findInfo', {}, {}).save({'project_code':items.project_code}, function(res){			              
          if(res.errcode === 0 || res.errcode === 10003){
              console.log(res);
              $scope.a = res.data;
              //返回的字符串变成数组
              $scope.array = $scope.a.project_file.split(',');
              console.log($scope.array);
              for(var i = 0;i<$scope.array.length;i++){
                  if($scope.array[i]==''){
                      $scope.array.splice(i,1);
                  }
              }

              if($scope.a.city_project == '0'){
                  $scope.a.city_project_name = '区县项目'
              } else if($scope.a.city_project == '1'){
                  $scope.a.city_project_name = '市本级项目'
              } 
              if($scope.a.project_build == '0'){
                  $scope.a.project_build = '建设类'
              } else if($scope.a.project_build == '1'){
                  $scope.a.project_build = '非建设类'
              }
              if($scope.a.project_level=='0'){
                  $scope.a.project_level='国家'
              } else if($scope.a.project_level=='1'){
                  $scope.a.project_level='省'
              } else if($scope.a.project_level=='2'){
                  $scope.a.project_level='市'
              } 
              $scope.getGuideType($scope.a.project_type);
              // 材料
              console.log('材料');
              console.log(JSON.parse($scope.a.project_file));
              $scope.material = JSON.parse($scope.a.project_file);
              if($scope.material.aa){
                $scope.array1 = $scope.material.aa;
                dic.aa = $scope.array1;
              } 
              if($scope.material.bb){
                $scope.array2 = $scope.material.bb;
                dic.bb = $scope.array2;
              } 
              $scope.array3 = $scope.material.cc;
              dic.cc = $scope.array3;
              $scope.array4 = $scope.material.dd;
              dic.dd = $scope.array4;
              $scope.array5 = $scope.material.ee;
              dic.ee = $scope.array5;
              $scope.array6 = $scope.material.ff;
              dic.ff = $scope.array6;
              $scope.array7 = $scope.material.gg;
              dic.gg = $scope.array7;

          }else{
              alert(res.errmsg);
          }
      });
  }
  $scope.getInfo();
  $scope.getNoticeList = function(){
      $resource('/api/as/ggc/reviewGuide/findCompanysList', {}, {}).save({}, function(res){
          if(res.errcode != 0){ 
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          console.log(res);
          $scope.noticeArr = res.data;
      });
  }
  $scope.getNoticeList();
  $scope.getRecommendName = function(recommend_type){
    for(var i = 0; i < $scope.officeFileArr.length; i++){
      var array = $scope.officeFileArr[i].id;
      array.forEach(element => {
        if(recommend_type == element){
          $scope.a.recommend_type_name = $scope.officeFileArr[i].name;
          console.log($scope.officeFileArr[i].name);
        }
      });
    }
  }
  // 责任处室
  $scope.officeFileArr = [
      {name:'规划发展处',value:'3', id : ['8', '9']},
      {name:'行业管理处  ',value:'6', id : ['3', '4']},
      {name:'人事编制处 ',value:'1', id : ['1', '2']},
      {name:'政策法规处 ',value:'2', id : ['3', '4']},
      {name:'区域合作处',value:'4', id : ['5', '6', '7']},
      {name:'市场开发处 ',value:'5', id : ['1', '2']},
      {name:'产业发展处',value:'7', id : ['8', '9']},
      {name:'特色旅游处',value:'8', id : ['5', '6', '7']},
      {name:'旅游质量监督管理所',value:'9', id : ['3', '4']},
      {name:'旅游产业发展服务中心',value:'10', id : ['8', '9']},
      {name:'机关党委',value:'11', id : ['5', '6', '7']},
      {name:'办公室',value:'12', id : ['5', '6', '7']}
  ]
  // 公告类型
$scope.typeFileArr = [
    {name:'旅游龙头项目',value:'0', id : '1'},
    {name:'旅游集聚区项目',value:'1', id : '2'},
    {name:'旅游集群项目',value:'2', id : '3'},
    {name:'全域旅游示范区项目',value:'3', id : '4'},
    {name:'特色旅游休闲街区项目',value:'4', id : '5'},
    {name:'特色旅游产业园区项目',value:'5', id : '6'},
    {name:'特色旅游人才培训基地项目',value:'6', id : '7'},
    {name:'特色旅游创客孵化基地项目',value:'7', id : '8'},
    {name:'离境退税项目',value:'8', id : '9'},
    {name:'景区提升工程项目',value:'9', id : '1'},
    {name:'旅游度假区项目',value:'10', id : '2'},
    {name:'乡村旅游项目',value:'11', id : '3'},
    {name:'旅游公共服务体系项目',value:'12', id : '4'},
    {name:'旅游公共交通体系项目',value:'13', id : '5'},
    {name:'旅游智慧化项目',value:'14', id : '6'},
    {name:'旅游节庆活动项目',value:'15', id : '7'},
    {name:'旅游展示活动项目',value:'16', id : '8'},
    {name:'旅游惠民活动项目',value:'17', id : '9'},
    {name:'旅游体制改革项目',value:'18', id : '8'},
    {name:'旅游招徕补贴项目',value:'19', id : '9'},
    {name:'旅游品牌奖励项目',value:'20', id : '1'},
    {name:'宣传营销项目',value:'21', id : '2'},
    {name:'旅游产品研发项目',value:'22', id : '3'},
    {name:'课题调查研究项目',value:'23', id : '4'},
    {name:'区域旅游合作项目',value:'24', id : '5'},
    {name:'旅游招商项目',value:'25', id : '6'},
    {name:'行业管理项目',value:'26', id : '7'},
    {name:'满意度评价项目',value:'27', id : '8'},
    {name:'其他项目',value:'28', id : '9'}     
]
  $scope.getGuideType = function(guide_type){
      $scope.typeFileArr.forEach(element => {
        if(guide_type == element.value){
          $scope.a.project_type_name = element.name;
        }
      });
  }
  $scope.del=function(index, number, str){
    console.log(index, number, str);
    if(number == '1'){
      $scope.array1.splice(index, 1);
      dic.aa = $scope.array1;
    }
    if(number == '2'){
      $scope.array2.splice(index, 1);
      dic.bb = $scope.array2;
    }
    if(number == '3'){
      $scope.array3.splice(index, 1);
      dic.cc = $scope.array3;
    }
    if(number == '4'){
      $scope.array4.splice(index, 1);
      dic.dd = $scope.array4;
    }
    if(number == '5'){
      $scope.array5.splice(index, 1);
      dic.ee = $scope.array5;
    }
    if(number == '6'){
      $scope.array6.splice(index, 1);
      dic.ff = $scope.array6;
    }
    if(number == '7'){
      $scope.array7.splice(index, 1);
      dic.gg = $scope.array7;
    } if(number == '8'){
      $scope.array8.splice(index, 1);
      dic.hh = $scope.array8;
    }
    if(number == '9'){
      $scope.array9.splice(index, 1);
      dic.ii = $scope.array9;
    }
    console.log(dic);
  }
  $scope.arr = [];
  var dic = {};
  $scope.image = function(aa){
    var para = $state.get('app.imageupload');
    //设置上传文件夹，以自己业务命名
    angular.extend(para, {
      resolve : {  
        'dir' : function(){
          return 't1';
        }
      } 
    })
    var modalInstance = $modal.open(para);
    modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
      console.log('modal is opened');  
    });  
    modalInstance.result.then(function(result) {  
      if(aa == '1'){ // 材料1
        $scope.array1 = result;
        dic.aa = $scope.array1;
        console.log(dic);
      } else if(aa == '2'){
        $scope.array2 = result;
        dic.bb = $scope.array2;
        console.log(dic);
      } else if(aa == '3'){
        $scope.array3 = result;
        dic.cc = $scope.array3;
        console.log(dic);
      } else if(aa == '4'){
        $scope.array4 = result;
        dic.dd = $scope.array4;
        console.log(dic);
      } else if(aa == '5'){
        $scope.array5 = result;
        dic.ee = $scope.array5;
        console.log(dic);
      } else if(aa == '6'){
        $scope.array6 = result;
        dic.ff = $scope.array6;
        console.log(dic);
      } else if(aa == '7'){
        $scope.array7 = result;
        dic.gg = $scope.array7;
        console.log(dic);
      } else if(aa == '8'){
        $scope.array8 = result;
        dic.hh = $scope.array8;
        console.log(dic);
      } else if(aa == '9'){
        $scope.array9 = result;
        dic.ii = $scope.array9;
        console.log(dic);
      }
      // $scope.a.project_file = $scope.array.join(',');
    }, function(reason) {  
      console.log(reason);// 点击空白区域，总会输出backdrop  
      // click，点击取消，则会暑促cancel  
      $log.info('Modal dismissed at: ' + new Date());  
    }); 
  };
  // 提交
  $scope.submit = function(){
    console.log(dic);
    console.log(JSON.stringify(dic));
    console.log($scope.a);
    $scope.a.project_file = JSON.stringify(dic);
      if($scope.a.project_name==null||$scope.a.project_name==''||$scope.a.project_name==undefined){
          alert('请填写项目名称');
          return;
      }
      if($scope.a.project_file==null||$scope.a.project_file==''||$scope.a.project_file==undefined){
          alert('请上报材料');
          return;
      }
      if (confirm('请确认资料是否修改完整,一经申报,无法修改!!!!!')){
        $resource('/api/ac/ggc/reviewCompanyProjectService/createCompanyProject', {}, {}).save({'project_name' : $scope.a.project_name, 'project_code' : $scope.a.project_code, 'project_file' : $scope.a.project_file}, function(res){
            if(res.errcode === 0){ 
                $resource('/api/as/ggc/reviewCompanyProject/updateApplyRe', {}, {}).save($scope.a, function(res){
                    if(res.errcode === 0){ 
                        toaster.success({title:"",body:'申报成功'});
                        $resource('/api/as/ggc/reviewPlanning/insertReviewCompanyProjectLog', {}, {}).save({'project_code' : $scope.a.project_code, 'check_state' : '0'}, function(res){			              
                            if(res.errcode === 0 || res.errcode === 10003){
                                console.log(res);
                            }else{
                                alert(res.errmsg);
                            }
                        });
                        $modalInstance.close();
                    }else{
                        toaster.error({title:"",body:res.errmsg});
                    }
                });
            }else{
                toaster.error({title:"",body:res.errmsg});
            }
        });
      }
    }
  
};
